<?php
/**
 * Created by PhpStorm.
 * User: 孙克强
 * Date: 2018/1/24
 * Time: 10:38
 */
class userRole_model extends CI_Model{
    /**
     * User_model constructor.
     * 构造函数，加载数据库配置文件
     */
    public function __construct() {
        $this->load->database();
    }

    /**
     * @param $user_id
     * @return mixed
     * 查询user_role
     */
    public function getAll($user_id){
        $query = $this->db->get_where('user_role',array('user_id'=>$user_id));
        return $query->result_array();
    }

    /**
     * @param $user_id
     * 删除
     */
    public function del($user_id){
        $this->db->delete('user_role',array('user_id'=>$user_id));
    }

    /**
     * @param $data
     * 添加
     */
    public function addUserRole($user_id,$role_id){
        $data = [
            'user_id' => $user_id,
            'role_id' => $role_id
        ];
        $this->db->insert('user_role',$data);
    }

    /**
     * 新加载一个userRole数据
     * @param $user_id
     */
    public function newUserRole($user_id){
        $data = array('user_id'=>$user_id);
        $this->db->insert('user_role',$data);
    }
}